package com.hs.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hs.server.domain.VehQueuexxb;
import com.hs.server.mapper.VehQueuexxbMapper;
import com.hs.server.mapper.VehZnshzlzpxxMapper;
import com.hs.server.service.VehQueuexxbService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author: chenjiarui
 * @Date: 2021-07-08 16:29
 */
@Service
public class VehQueuexxbServiceImpl extends ServiceImpl<VehQueuexxbMapper, VehQueuexxb> implements VehQueuexxbService {
    @Autowired
    VehQueuexxbMapper vehQueueMapper;
    @Autowired
    VehZnshzlzpxxMapper vehZnshzlzpxxMapper;


    @Override
    public int addVehQueuexxb(VehQueuexxb vehQueuexxb) {
        QueryWrapper<VehQueuexxb> qw = new QueryWrapper<>();
        qw.eq("lsh",vehQueuexxb.getLsh());
        qw.eq("zpzl",vehQueuexxb.getZpzl());
        if (vehQueueMapper.selectCount(qw)==0)
            return vehQueueMapper.insert(vehQueuexxb);
        else
            return vehQueueMapper.update(vehQueuexxb,qw);
    }

    @Override
    public int updateVehQueuexxb(VehQueuexxb vehQueuexxb) {
        QueryWrapper<VehQueuexxb> qw = new QueryWrapper<>();
        qw.eq("lsh",vehQueuexxb.getLsh());
        qw.eq("zpzl",vehQueuexxb.getZpzl());
        return vehQueueMapper.update(vehQueuexxb,qw);
    }

    @Override
    public int updateWorkReviewing(String lsh,String zpzl) {
        return vehQueueMapper.updateZtByLsh(lsh,zpzl);
    }

    @Override
    public void delWork(String lsh,String zpzl) {
        QueryWrapper<VehQueuexxb> qw = new QueryWrapper();
        qw.eq("lsh",lsh);
        qw.eq(StringUtils.isNotBlank(zpzl),"zpzl",zpzl);
        if (vehQueueMapper.selectCount(qw)>0)
            vehQueueMapper.delete(qw);
    }

    @Override
    public int getTaskNum() {
        return vehQueueMapper.getWorkNum();
    }

    @Override
    public List<VehQueuexxb> getVehQueuexxb(String lsh) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if(StringUtils.isNotBlank(lsh)) {
            queryWrapper.eq("lsh", lsh);
        }
        return vehQueueMapper.selectList(queryWrapper);
    }

    @Override
    public VehQueuexxb getNewWork() {
        return vehQueueMapper.getNewWork();
    }

    @Override
    public void updateShzt() {
        vehQueueMapper.updateShzt();
    }

    @Override
    public String judgeTaskFinish() {
        return vehQueueMapper.judgeTaskFinish();
    }
}
